package com.jay.tools.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tan on 2017/4/6 006.
 */
public abstract class BaseMyAdapter<M> extends BaseAdapter {

    protected Context mContext;
    protected LayoutInflater mInflater;
    protected List<M> mDatas;

    protected IAdapterClick<M> mListener;

    public BaseMyAdapter(Context context) {
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
        mDatas = new ArrayList<>();
    }

    public void setDatas(List<M> datas) {
        mDatas = datas;
        notifyDataSetChanged();
    }

    public List<M> getDatas() {
        return mDatas;
    }

    public void setOnItemClick(IAdapterClick<M> click){
        mListener = click;
    }

    @Override
    public int getCount() {
        return null == mDatas ? 0 : mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getMyView(position, convertView, parent);
    }

    protected abstract View getMyView(int position, View convertView, ViewGroup parent);

}
